import themeState from './themeState';
// eslint-disable-next-line no-unused-vars
import themeData from './themeData';

const colorRegExp = /{([^{}}]+)}/g;

/**
 * @name: 获取查看当前themeData
 * @return {themeData}
 */
export function getThemeData() {
  return themeState.data;
}

/**
 * @name: 根据theme变量获取颜色
 * @param {String} color
 * @return {String}
 * @example getThemeColor('{primary}')
 */
export function getThemeColor(color) {
  const colorKey = String(color);
  if (colorKey.match(colorRegExp)) {
    return colorKey.replace(/{([^{}}]+)}/g, (_str, k) => {
      return themeState.data[k] || k;
    });
  }
  return color;
}

/**
 * @name: 替换theme
 * @param {themeData} theme
 * @return {void}
 */
export function changeTheme(theme) {
  themeState.data = Object.assign({}, themeState.data, theme);
}
